package bb.lanxing.adapter.mine;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import bb.lanxing.R;

public class MineListAdapter extends RecyclerView.Adapter<MineListAdapter.ViewHolder> {
    private final int[] mineListIcon = { R.drawable.ic_mine_history, R.drawable.ic_mine_career_record,
            R.drawable.ic_mine_medal, R.drawable.ic_mine_career, R.drawable.ic_mine_order };
    private final int[] mineListName = { R.string.mine_title_history, R.string.mine_career_record,
            R.string.mine_title_ranking, R.string.mine_sports_career, R.string.mine_order };

    private OnItemClickListener listener;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        Context context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_mine, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.icon.setImageResource(mineListIcon[position]);
        holder.name.setText(mineListName[position]);
        holder.itemView.setOnClickListener(v -> {
            if (listener != null) {
                listener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mineListIcon.length;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView icon;
        TextView name;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.icon);
            name = itemView.findViewById(R.id.name);
        }
    }
}
